package com.example.book_subscribe.adminBookList.controlle;

import com.example.book_subscribe.adminBookList.dto.AdminBookDetailDto;
import com.example.book_subscribe.adminBookList.dto.AdminBookListDto;
import com.example.book_subscribe.adminBookList.dto.AdminBookNameDto;
import com.example.book_subscribe.adminBookList.mapper.AdminBookListMapper;
import com.example.book_subscribe.adminBookList.result.*;
import com.example.book_subscribe.mine.result.MineResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.UUID;

@RestController
public class AdminBookList {
    @Resource
    private AdminBookListMapper AdminBookListMapper;

    @PostMapping("/AdminBookList")
    public ArrayList<AdminBookListResult> getBookList(@RequestBody AdminBookListDto adminBookListDto) {
        long offset = (adminBookListDto.getCurrent() - 1) * adminBookListDto.getLimit();
        ArrayList<AdminBookListResult> bookResults = new ArrayList<>();
        bookResults = AdminBookListMapper.searchAdminBookList(adminBookListDto, offset);
        return bookResults;
    }

    @PostMapping("/getBooksNumber")
    public int getBooksNumber(@RequestBody AdminBookListDto dto) {
        return AdminBookListMapper.countBooks(dto);
    }

    @PostMapping("/getAdminBookDetail")
    public AdminBookDetailResult getAdminBookDetail(@RequestBody AdminBookNameDto adminBookNameDto) {
        AdminBookDetailResult bookResults = AdminBookListMapper.getAdminBookDetail(adminBookNameDto.getBookId());
        return bookResults;
    }

    @PostMapping("/getAllCategory")
    public ArrayList<AllCategoryResult> getAllCategory() {
        ArrayList<AllCategoryResult> bookResults = new ArrayList<>();
        bookResults = AdminBookListMapper.searchAllCategory();
        return bookResults;
    }

    @PostMapping("/updateBookDetail")
    public String updateBookDetail(@RequestBody AdminBookDetailDto AdminBookDetailDto) {
        AdminBookListMapper.updateBookDetails(AdminBookDetailDto);
        return "请求成功";
    }

    @PostMapping("/insertBookDetail")
    public String insertBookDetail(@RequestBody AdminBookDetailDto AdminBookDetailDto) {
        String uuid = UUID.randomUUID().toString();
        AdminBookDetailDto.setBookId(uuid);
        AdminBookListMapper.insertBookDetails(AdminBookDetailDto);
        return "新增成功";
    }

    @PostMapping("/deleteBookDetail")
    public String deleteBookDetail(@RequestBody AdminBookNameDto adminBookNameDto) {
        AdminBookListMapper.deleteBookDetails(adminBookNameDto.getBookId());
        return "删除成功";
    }

    @PostMapping("/checkBookExist")
    public boolean checkBookExist(@RequestBody AdminBookNameDto adminBookNameDto) {
        boolean istrue = AdminBookListMapper.searchBookExist(adminBookNameDto.getBookId());
        return istrue;
    }

    @GetMapping("/getAllUser")
    public ArrayList<AdminUserAllResult> getAllUser() {
        ArrayList<AdminUserAllResult> results = new ArrayList<>();
        results = AdminBookListMapper.getAllUser();
        return results;
    }

    @PostMapping("/getAllAdminComment")
    public ArrayList<AdminAllCommentResult> getAdminAllComment(@RequestBody AdminBookNameDto adminBookNameDto) {
        ArrayList<AdminAllCommentResult> results = new ArrayList<>();
        results = AdminBookListMapper.getAllComment(adminBookNameDto.getBookId());
        return results;
    }
    @PostMapping("/getAllUserComment")
    public ArrayList<AdminAllUserCommentsResult> getAllUserComment(@RequestBody AdminBookNameDto adminBookNameDto) {
        ArrayList<AdminAllUserCommentsResult> results = new ArrayList<>();
        results = AdminBookListMapper.getAllUserComment(adminBookNameDto.getBookId());
        return results;
    }

    @PostMapping("/getAllUserSubscribe")
    public ArrayList<AdminAllUserSubscribesResult> getAllUserSubscribe(@RequestBody AdminBookNameDto adminBookNameDto) {
        ArrayList<AdminAllUserSubscribesResult> results = new ArrayList<>();
        results = AdminBookListMapper.getAllUserSubscribe(adminBookNameDto.getBookId());
        return results;
    }
}
